﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using JQuery.WebKit.Base;

#region resources
[assembly: WebResource("JQuery.WebKit.JMenu.JMenu.js", "text/javascript")]
[assembly: WebResource("JQuery.WebKit.JMenu.JMenu.min.js", "text/javascript")]
[assembly: WebResource("JQuery.WebKit.JMenu.JMenu.css", "text/css")]
#endregion
namespace JQuery.WebKit
{
    //[Designer("System.Web.UI.Design.WebControls.PanelContainerDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
    [ParseChildren(typeof(JMenuItem), DefaultProperty = "MenuItems", ChildrenAsProperties = true)]
    public class JMenu : WebControlBase, INamingContainer
    {
        [PersistenceMode(PersistenceMode.InnerProperty),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public List<JMenuItem> MenuItems
        {
            get;
            private set;
        }

        public JMenu()
            : base(HtmlTextWriterTag.Ul)
        {
            MenuItems = new List<JMenuItem>();
        }

        protected override void CreateChildControls()
        {
            MenuItems.ForEach(item => item.InstantiateIn(this));
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.RegisterJQueryResource(Globals.ResourcePaths.JQueryLibraries.JQueryPlugins.JQueryCookie);
            base.RegisterJQueryResource("JQuery.WebKit.JMenu.JMenu.js");
            base.RegisterCSSResource("JQuery.WebKit.JMenu.JMenu.css");
            base.OnPreRender(e);
        }

        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            base.CssClass = "menu";
            base.RenderBeginTag(writer);
            //writer.Write(string.Format("<ul id='{0}_Menu' class='menu'>", this.ClientID));
        }

        public override void RenderEndTag(HtmlTextWriter writer)
        {
            //writer.Write("</ul>");
            base.RenderEndTag(writer);
        }
    }
}
